﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MathService.DSP.Signals.Noice
{
    public class RandomSignal : DigitalSignal
    {
        private Random f_RandomGenerator = new Random(DateTime.Now.TimeOfDay.Milliseconds);

        private double f_D;
        private double f_Offset;

        public double D { get { return f_D; } set { f_D = value; } }
        public double Offset { get { return f_Offset; } set { f_Offset = value; } }

        public override double this[int n]
        {
            get { return (f_RandomGenerator.NextDouble() * f_D) - f_D / 2 + f_Offset; }
            set { throw new NotSupportedException("Не поддерживается для случайного сигнала"); }
        }

        public override double[] Samples
        {
            get
            {
                Initialize();
                return base.Samples;
            }
            set { base.Samples = value; }
        }

        public RandomSignal(double D, double Offset, double dx, int N)
            : base(dx, N)
        {
            f_D = D;
        }

        public void Initialize()
        {
            for(int i = 0, i_Length = SamplesCount; i < i_Length; i++)
                f_Samples[i] = this[i]; 
        }
    }
}
